﻿using AutoMapper;
using MediatR;
using S.EarTag.API.Mediator.MediatorCommand.AppearanceCommand;
using S.EarTag.Domain.Model;
using S.EarTag.Infrastructure.Repository.Interface.IEarTagRepository;

namespace S.EarTag.API.Mediator.MediatorCommandHandler.AppearanceCommandHandler
{
    public class AppearanceUpdateCommandHandler : IRequestHandler<AppearanceUpdateCommand, bool>
    {
        private readonly IAppearanceModelRepository _appearanceModelRepository;
        private readonly IMapper _mapper;
        public AppearanceUpdateCommandHandler(IAppearanceModelRepository appearanceModelRepository,IMapper mapper)
        {
            _appearanceModelRepository= appearanceModelRepository;
            _mapper= mapper;
        }
        /// <summary>
        /// 修改品相测量数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<bool> Handle(AppearanceUpdateCommand request, CancellationToken cancellationToken)
        {

            request.MeasureDate=request.MeasureDate.AddDays(1);
            return await _appearanceModelRepository.UpdateAsync(_mapper.Map<AppearanceModel>(request));
        }
    }
}
